﻿using IOP.SgrA.GLSL;
using IOP.SgrA.SilkNet.Vulkan;
using IOP.SgrA.SilkNet.Vulkan.Scripted;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VkSample113
{
    [ShaderVersion("460")]
    [GLSLExtension("GL_ARB_separate_shader_objects : enable")]
    [GLSLExtension("GL_ARB_shading_language_420pack : enable")]
    public partial class LandFrag : GLSLFrag
    {
        [SampledImage(0, 0, DescriptorSetTarget.RenderObject)]
        public sampler2D tCaodi {  get; set; }
        [SampledImage(0, 1, DescriptorSetTarget.RenderObject)]
        public sampler2D tSand {  get; set; }

        [ShaderInput(0)]
        public vec2 inTexCoor { get; set; }
        [ShaderInput(1)]
        public float landHeight {  get; set; }
        [FragOutput(0, false)]
        public vec4 outColor {  get; set; }

        public override void main()
        {
            float height1 = 90;
            float height2 = 120;
            vec4 colorCaodi = textureLod(tCaodi, inTexCoor, 0.0f);//采样出草地颜色
            vec4 colorSand = textureLod(tSand, inTexCoor, 0.0f);//采样出沙滩颜色
            if (landHeight < height1)
            {//绘制沙滩
                outColor = colorSand;
            }
            else if (landHeight < height2)
            {//绘制混合颜色
                float radio = (landHeight - height1) / (height2 - height1);
                outColor = mix(colorCaodi, colorSand, 1 - radio);
            }
            else
            {//绘制草地
                outColor = colorCaodi;
            }
        }
    }
}
